home *** CD-ROM | disk | FTP | other *** search
/ Mac Cube 4: Multimedia Applications / MacCube Volume 4: Multimedia Applications.iso / Graphics / NIH Image Folder / Macros / Input⁄Output Macros < prev    next >
Text File  |  1993-08-06  |  10KB  |  412 lines

  1. macro 'Save using Time as Name…';
  2. {Note: Colons are not allowed in file names.}
  3. var
  4.   year,month,day,hour,minute,second,DayOfWeek:integer;
  5. begin
  6.   GetTime(year,month,day,hour,minute,second,DayOfWeek);
  7.   SaveAs(year-1900:2,'-',month:2,'-',day:2,
  8.          '/',hour:2,'-'minute:2,'-',second:2);
  9. end;
  10.  
  11.  
  12. macro 'Open with selection… [O]';
  13. begin
  14.   if nPics>0 then KillRoi; {Save Selection}
  15.   Open('');                {Prompt for file name}
  16.   RestoreROI;              {Transfer selection to new window}
  17. end;
  18.  
  19.  
  20. macro 'Save All…';
  21. {
  22. Saves all currently open images in a folder using '001', '002', etc.
  23. as the file names. The save file dialog box will be displayed once
  24. (and only once) so that you can specify the folder to save the files in.
  25. Leave the file name blank(e.g. SaveAs('')) to get a dialog box for each file.
  26. }
  27. var
  28.   n:integer;
  29. begin
  30.   RequiresVersion(1.45);
  31.   for n:=1 to nPics do begin
  32.     SelectPic(n);
  33.     SaveAs(n:3);
  34.     {Export(n:3);}
  35.   end;
  36. end;
  37.  
  38.  
  39. macro 'Import FITS…';
  40. {
  41. This is an example of how to decode an image file header. In this case, the header is 2880 bytes long and bytes 266-269 contain the width(ASCII) and bytes
  42. 246-249 cantain the height. Refer to "FITS:A Flexible Image Transport System",
  43. Astronomy and Astrophysics Supplement Series 44, 1981, 363-370.
  44. }
  45. var
  46.   width,height,offset,i,d,m:integer;
  47. begin
  48.   width:=512; 
  49.   height:=1;
  50.   offset:=0;
  51.   SetImport('8-bit'); 
  52.   SetCustom(width,height,offset);
  53.   Import(''); {Read in header as an image, prompting for the file name.}
  54.   if not ((GetPixel(108,0)=49) and (GetPixel(109,0)=54)) then begin
  55.     {BITPIX<>16}
  56.     PutMessage('This macro only reads 16-bit FITS files');
  57.     SelectPic(nPics); Dispose;
  58.     exit;
  59.   end;
  60.   m:=1000;
  61.   width:=0;
  62.   for i:=266 to 269 do begin
  63.     d:=GetPixel(i,0);
  64.     if d=32 then d:=48;
  65.     d:=d-48;
  66.     width:=width+d*m;
  67.     m:=m/10;
  68.   end;
  69.   m:=1000;
  70.   height:=0;
  71.   for i:=346 to 349 do begin
  72.     d:=GetPixel(i,0);
  73.     if d=32 then d:=48;
  74.     d:=d-48;
  75.     height:=height+d*m;
  76.     m:=m/10;
  77.   end;
  78.   SelectPic(nPics); {The ID of the last window opened is equal to nPics.}
  79.   Dispose;
  80.   offset:=2880;
  81.   SetImport('16-bit Signed; Calibrate; Autoscale');
  82.   SetCustom(width,height,offset);
  83.   Import('');  {No prompt this time; Import remembers the name.}
  84.   FlipVertical;
  85. end;
  86.  
  87.  
  88. macro 'Import Image TIFF File…';
  89. {
  90. As an example of how to import a foreign file format, this macro reads
  91. the TIFF files created by Image. The format of an Image TIFF file
  92. is described in Appendix E of the Image manual.
  93. }  
  94. var
  95.   width,height,offset:integer;
  96. begin
  97.   width:=768; 
  98.   height:=1;
  99.   offset:=0;
  100.   SetImport('8-bit'); 
  101.   SetCustom(width,height,offset);
  102.   Import(''); {Read in header as an image, prompting for the file name.}
  103.   if not ((GetPixel(0,0)=77) and (GetPixel(0,0)=77)) then begin  {'MM'}
  104.     PutMessage('This is not a TIFF file.');
  105.     SelectPic(nPics); Dispose;
  106.     exit;
  107.   end;
  108.   width := (GetPixel(30,0)*256) + GetPixel(31,0);
  109.   height := (GetPixel(42,0)*256) + GetPixel(43,0);
  110.   SelectPic(nPics);  {The ID of the last window opened is equal to nPics.}
  111.   Dispose;
  112.   offset:=768;
  113.   SetCustom(width,height,offset);
  114.   Import('');  {No prompt this time; Import remembers the name.}
  115. end;
  116.  
  117.  
  118. macro 'Import Multiple Images per File…';
  119. {
  120. Imports a series of 256x256 images contained in a single file, in this
  121. case an NIH Image stack with an arbitrary number of 256x256 slices.
  122. }
  123. var
  124.   offset,i,PicSize,HdrSize,width,height:integer;
  125. begin
  126.   HdrSize:= 768;
  127.   width:= 256;
  128.   height:=256;
  129.   PicSize:=width*height;
  130.   offset:=HdrSize;
  131.   SetImport('8-bit');
  132.   for I:=1 to 100 do begin  {Macro will terminate at eof}
  133.     SetCustom(width,height,offset);
  134.     Import('');
  135.     offset:=offset+PicSize;
  136.   end;
  137. end;
  138.  
  139.  
  140. macro 'Import PET…';
  141. var
  142.   offset,i,PicSize,HdrSize,width,height:integer;
  143. begin
  144.   HdrSize:= 0;
  145.   width:= 128;
  146.   height:=128;
  147.   PicSize:=width*height;
  148.   offset:=HdrSize;
  149.   SetImport('8-bit');
  150.   for I:=1 to 100 do begin  {Macro will terminate at eof}
  151.     SetCustom(width,height,offset);
  152.     Import('');
  153.     offset:=offset+PicSize;
  154.   end;
  155. end;
  156.  
  157.  
  158. macro 'Convert Files…';
  159. {
  160. Converts a set of raw data files(all in the same folder) with names
  161. in the form raw.001, raw.002, etc to TIFF or PICT.  As long as the
  162. converted files are saved in the same folder, you should
  163. only see two file dialog boxes(one for the first Import and one for
  164. the first SaveAs).
  165. }
  166. Var
  167.   i,nFiles:integer;
  168. begin
  169.   nFiles:=GetNumber('Number of files:',5);
  170.   for i:=1 to nFiles do begin
  171.     Import('raw.',i:3);
  172.     SetPicName('file',i:3);
  173.     SaveAs;
  174.     Dispose;
  175.   end;
  176. end;
  177.  
  178.  
  179. macro 'Import IPLab File';
  180. var
  181.    width,height,offset:integer;
  182. begin
  183.    width:=100; 
  184.    height:=1;
  185.    offset:=0;
  186.    SetImport('8-bit'); 
  187.    SetCustom(width,height,offset);
  188.    Import(''); {Read in header as an image, prompting for file name.}
  189.    width := (GetPixel(8,0)*256) + GetPixel(9,0);
  190.    height := (GetPixel(12,0)*256) + GetPixel(13,0);
  191.    Dispose;  
  192.    offset:=2120;  {The IPLab offset}
  193.    SetImport('16-bit Signed; Calibrate; Autoscale');
  194.    SetCustom(width,height,offset);
  195.    Import('');  {No prompt this time; Import remembers the name.}
  196. end;
  197.  
  198.  
  199. procedure ShowBioRadInfo;
  200. {Displays the contents of the 480(?) byte header at}
  201. {the end of Biorad MRC 600 Z Series files.}
  202. var
  203.   MaxInfoSize,offset:integer;
  204.   ch:string;
  205. begin
  206.   MaxInfoSize:=480;
  207.   SetCustom(MaxInfoSize,1,HdrSize+Width*Height);
  208.   SetImport('8-bit'); {Don't invert}
  209.   Import('');
  210.   GetRow(0,0,MaxInfoSize);
  211.   Dispose;
  212.   SetNewSize(460,100);
  213.   SetForeground(255);
  214.   SetBackground(0);
  215.   MakeNewWindow('Info');
  216.   SetCursor('Watch');
  217.   SetFont('Monaco');
  218.   SetText('With background; Left Justified');
  219.   SetFontSize(12);
  220.   MoveTo(8,10);
  221.   for i:=0 to MaxInfoSize-1 do begin
  222.     offset:=i mod 96;
  223.     if offset=0 then writeln;
  224.     ch:=chr(LineBuffer[i]);
  225.     if (offset=2) and (ord(ch)=0) then exit;
  226.     if (offset>=16) and (offset<=95) and (ord(ch)>=32) and (ord(ch)<=126)
  227.       then write(ch);
  228.   end;
  229. end;
  230.  
  231.  
  232. macro 'Import Biorad MRC 600 Z Series…';
  233. {
  234. Imports a Z series(multiple images per file) from a Biorad MRC 600
  235. confocal microscope.  The width, height and number of images are
  236. extracted from the first 3 16-bit word in the 76 byte header and
  237. the file name is extracted from bytes 18-23 of the header. Note that
  238. the Undo and Clipboard buffers must be set to 384K to work with
  239. the typical 768x512 Biorad images.
  240. }
  241. var
  242.   width,height,nImages,offset,hdrsize,i,start,picsize:integer;
  243. begin
  244.   RequiresVersion(1.50);
  245.   width:=512; 
  246.   height:=1;
  247.   offset:=0;
  248.   SetImport('8-bit'); 
  249.   SetCustom(width,height,offset);
  250.   Import(''); {Read header}
  251.   GetPicSize(width,height);
  252.   if (width<>512) or (height<>1) then begin
  253.     Dispose;
  254.     PutMessage('Please to not change width, height, etc. in the Import dialog box.');
  255.     exit;
  256.   end;
  257.   width:=GetPixel(0,0)+GetPixel(1,0)*256;
  258.   height:=GetPixel(2,0)+GetPixel(3,0)*256;
  259.   nImages:=GetPixel(4,0)+GetPixel(5,0)*256;
  260.   Dispose;
  261.   hdrsize:= 76;
  262.   picsize:=width*height;
  263.   if (width<128) or (width>2048) or (height<128) or (height>2048) or (nImages<1) or (nImages>256) then begin
  264.     PutMessage('This does not seem to be a Biorad MRC 600 Z Series file.');
  265.     exit;
  266.   end;
  267.   start:=GetNumber('Starting image:',1);
  268.   offset:=HdrSize+(start-1)*PicSize;
  269.   SetImport('8-bit; Invert'); 
  270.   SetCustom(width,height,offset,nimages);
  271.   Import('');
  272.   for i:=1 to nSlices do begin
  273.     SelectSlice(i);
  274.     Invert;
  275.     ChangeValues(0,0,1);
  276.     ChangeValues(255,255,254);
  277.   end;
  278.   ShowBioRadInfo;
  279. end;
  280.  
  281.  
  282. macro 'Import from IBAS';
  283. var
  284.    width,height,offset:integer;
  285. begin
  286.    width:=128; 
  287.    height:=1;
  288.    offset:=0;
  289.    SetImport('8-bit'); 
  290.    SetCustom(width,height,offset);
  291.    Import(''); {Read in header as an image, prompting for file name.}
  292.    width := (GetPixel(7,0)*256) + GetPixel(6,0);
  293.    height := (GetPixel(9,0)*256) + GetPixel(8,0);
  294.    Dispose(nPics);  {The ID of the last window opened = nPics.}
  295.    offset:=128;  {The IBAS offset}
  296.    SetImport('8-bit; Calibrate; Autoscale');
  297.    SetCustom(width,height,offset);
  298.    Import('');  {No prompt this time; Import remembers the name.}
  299.    Invert
  300.    SetScaling ('Bilinear');
  301.    SetScaling ('New Window');
  302.    ScaleAndRotate (0.80, 1.0, 0);
  303. end;
  304.  
  305.  
  306. macro 'Import 64x64x64x16-bit SPECT Image…';
  307. {Imports a 64x64x64x16-bit headerless SPECT image into a stack.}
  308. var
  309.   width,height,nImages,hdrsize:integer;
  310. begin
  311.   RequiresVersion(1.50);
  312.   width:=64;
  313.   height:=64;
  314.   nImages:=64;
  315.   HdrSize:= 0;
  316.   SetImport('16-bit Unsigned, Swap Bytes');
  317.   {SetImportMinMax(0,2500);} {Uncomment to fix scale}
  318.   SetCustom(width,height,HdrSize,nImages);
  319.   Import('');
  320.  end;
  321.  
  322.  
  323. macro 'Import 8-bit 3D Image…';
  324. var
  325.   width,height,offset,nImages:integer;
  326. begin
  327.   RequiresVersion(1.50);
  328.   width:=GetNumber('Width:',256);
  329.   height:=GetNumber('Height:',256);
  330.   nImages:=GetNumber('Depth(number of slices):',128);
  331.   offset:=GetNumber('Offset(header size):',0);
  332.   SetImport('8-bit'); 
  333.   SetCustom(width,height,offset,nImages);
  334.   Import('');
  335. end;
  336.  
  337.  
  338. macro 'Open with scale set to 100 pixels/mm [S]';
  339. {Example of a way to open images and have the}
  340. {spatial scale always set the same way.}  
  341. begin
  342.   Open('');           {or Import('')}
  343.   SetScale(100,'mm'); {Change as needed}
  344. end;
  345.  
  346.  
  347. macro 'Load Synergy Image';
  348. begin
  349.    SetImport('8-bit'); 
  350.    SetCustom(512,480,16384);
  351.    Import('');
  352.    ChangeValues(0,0,1);
  353.    ChangeValues(255,255,254);
  354.    SetPalette('Rainbow');
  355. end;
  356.  
  357.  
  358. macro 'Import Siemens 3D MRI…';
  359. begin
  360.   RequiresVersion(1.50);
  361.   SetImport('16-bit Signed, Swap Bytes');
  362.   {SetImportMinMax(0,3000);} {Remove comments to fix scale}
  363.   SetCustom(256,256,0,127);
  364.   Import('');
  365. end;
  366.  
  367.  
  368. procedure ImportPhotoshop(offset:integer);
  369. {
  370. Imports a 24-bit, uncompressed Photoshop
  371. TIFF file into a 3-slice stack.
  372. }
  373. var
  374.   width,height,temp,stack,i,j:integer;
  375. begin
  376.   SetImport('8-bit; Invert');
  377.   width:=GetNumber('Width:',512);
  378.   height:=GetNumber('Height:',512);
  379.   SetCustom(3*width,height,offset,1);
  380.   Import('');
  381.   temp:=PicNumber;
  382.   SetNewSize(width,height);
  383.   MakeNewStack('RGB');
  384.   AddSlice;
  385.   AddSlice;
  386.   stack:=PicNumber;
  387.   for i:=0 to width-1 do begin
  388.     for j:=1 to 3 do begin
  389.       ChoosePic(temp);
  390.       GetColumn(3*i+(j-1),0,height);
  391.       ChoosePic(stack);
  392.       ChooseSlice(j);
  393.       PutColumn(i,0,height);
  394.     end;
  395.   end;
  396.   SelectSlice(1);
  397.   SelectPic(temp);
  398.   Dispose;
  399. end;
  400.  
  401. macro 'Import Photoshop 2.0 24-bit TIFF';
  402. begin
  403.   ImportPhotoshop(196);
  404. end;
  405.  
  406. macro 'Import Photoshop 2.5 24-bit TIFF';
  407. begin
  408.   ImportPhotoshop(598);
  409. end;
  410.  
  411.  
  412.